//
//  StoryContentViewModel.m
//  HLZhiHuDaily
//
//  Created by 胡林 on 16/3/1.
//  Copyright © 2016年 胡林. All rights reserved.
//

#import "StoryContentViewModel.h"

@implementation StoryContentViewModel
- (NSString *)imageURLString {
    return _storyModel.image;
}

-(NSAttributedString *)titleAttText {
    
    return [[NSAttributedString alloc] initWithString:_storyModel.title attributes:@{NSFontAttributeName:[UIFont boldSystemFontOfSize:21],NSForegroundColorAttributeName:[UIColor whiteColor]}];
}

- (NSString *)imaSourceText {
    return [NSString stringWithFormat:@"图片: %@",_storyModel.image_source];
}

- (NSString *)htmlStr {
    return [NSString stringWithFormat:@"<html><head><link rel=\"stylesheet\" href=%@></head><body>%@</body></html>",_storyModel.css[0],_storyModel.body];
}
- (NSString *)share_URL {
    return _storyModel.share_url;
}

- (NSNumber *)storyType {
    return _storyModel.type;
}

- (NSArray *)recommenders {
    return _storyModel.recommenders;
}
//通过id获取内容
- (void)getStoryContentWithStoryID:(NSNumber*)storyID {
    [RequestURL getRequestWithUrl:[NSString stringWithFormat:@"news/%@",[storyID stringValue]] parameters:nil success:^(id responseObject) {
        NSDictionary * dic = (NSDictionary * )responseObject;
        StoryContentModel * model = [[StoryContentModel alloc] initWithDictionary:dic];
        [self setValue:model forKey:@"storyModel"];
        _loadedStoryID = storyID;
        
    } failure:nil];

}
//获取上一篇内容
- (void)getPreviousStoryContent {
    NSInteger index = [_storiesID indexOfObject:_loadedStoryID];
    if (--index >= 0) {
        NSNumber* nextStoryID = [_storiesID objectAtIndex:index];
        [self getStoryContentWithStoryID:nextStoryID];
    }
}
//获取下一篇内容
- (void)getNextStoryContent {
    NSUInteger index = [_storiesID indexOfObject:_loadedStoryID];
    if (++index < _storiesID.count) {
        NSNumber* nextStoryID = [_storiesID objectAtIndex:index];
        [self getStoryContentWithStoryID:nextStoryID];
    }
}


@end
